<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		
		<script type="text/javascript">
			function changeImg(obj) {
				obj.src = "${pageContext.request.contextPath }/codeutil?aaa="+new Date().getTime();
			}
		</script>

		
		<style type="text/css">
			p{
				color: red;
				text-align: center;
			}
			
			span{
				color:red;
			}
		</style>
	</head>
	<body>
		<h1 style="text-align: center;">我的京东_注册</h1><hr/>
		
		<p>${error}</p>
		<form action="${pageContext.request.contextPath }/regist"
			  method="post" onsubmit="return bijiaopsd()">
			
			<table border="1" cellspacing="0" cellpadding="10" align="center">
					
					<tr>
						<td>用户名:</td>
						<td> <input type="text" name="username" value="${param.username}" onchange="cunzai(this)" size="30" maxlength="20"/> <span>${map.username }</span> </td>
					</tr>
					
					<tr>
						<td>密码:</td>
						<td> <input id="p1" type="password" name="password" size="30"/><span>${map.password }</span> </td>
					</tr>
					
					<tr>
						<td>重复密码:</td>
						<td> <input id="p2" type="password" name="password2" size="30"/> </td>
					</tr>

				<tr>
					<td>角色:</td>
					<td>
						<select name="role_id">
						<option value="1" ${param.role_id == 1?'selected':''}>顾客</option>
						<option value="2" ${param.role_id == 2?'selected':''}>商家</option>
					</select></td>
				</tr>
					<tr>
						<td>昵称:</td>
						<td> <input type="text" name="nickname" value="${param.nickname }" size="30"
									maxlength="20"/><span>${map.nickname }</span> </td>
					</tr>
					<tr>
						<td>邮箱:</td>
						<td> <input type="text" name="email" value="${param.email }"
									size="30"/><span>${map.email }</span> </td>
					</tr>
					<tr>
						<td>验证码:</td>
						<td> <input type="text" name="valistr"  size="30"/> </td>
					</tr>
					<tr>
						<td>  
							<input type="submit" value="注册" />
						</td>
						<td>  
							<img  onclick="changeImg(this)"  alt="xxx"
								  src="${pageContext.request.contextPath }/codeutil">
						</td>
					</tr>
			</table>
		</form>
	</body>
	
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.12.4.js"></script>

<script>

	function cunzai(obj) {

		var value = $(obj).val();
		$.post("${pageContext.request.contextPath}/cunzai",{'username':value} ,function(result){
			$(obj).next().html(result.message);
		},"json");

	}

	function bijiaopsd() {
		var value1 = $("#p1").val();
		var value2 = $("#p2").val();

		if(value1 != value2){
			alert("两次密码输入不一致");
			return false;
		}else{
			return true;
		}
	}
</script>
</html>
